import * as actions from '../actions/index';

function getInitialState() {
  // 页面初始化数据
  const initialState = {
    isLoadingBuild: true,
    buildResult: null,
    incompleteData: null,
    tableParams: {
      // start_time: null,
      // end_time: null,
      // users: [],
      build_language: '',
      issue_level_list: [],
      issue_type: 'indirect_dependency',
    },
    isStarting: false,
    // onchange和onOk控制不同值
    start_time: null,
    end_time: null,
    issueCount: 0,
    curCommitId: '',
  };
  return initialState;
}

const defaultAction = {
  type: 'doNothing',
};

export default function index(state = getInitialState(window.FORCE), action = defaultAction) {
  switch (action.type) {
    case actions.UPDATE_DATA:
      return { ...state, ...action.data };
    case actions.UPDATE_PARAM_DATA:
      return { ...state, tableParams: { ...state.tableParams, ...action.data } };
    case actions.RESET_DATA:
      return { ...getInitialState(window.FORCE) };
    default:
      return state;
  }
}
